{extend name="layout" /}

{block name="breadcrumb"}
<h2>{$title}{$typeName}</h2>
<ol class="breadcrumb">
    <li><a href="{:url('index/index')}">首页</a></li>
    <li><a href="{:url('lang/index')}">语种列表</a></li>
    <li><strong>{$lang}</strong></li>
    <li><strong>{$className}</strong></li>
    <li><strong>{$courseName}</strong></li>
    <li>
        <a href="{:url('index', ['classId' => $classId, 'courseType' => $courseType, 'type' => $type, 'lang' => $lang, 'className' => $className])}">{$typeName}列表</a>
    </li>
    <li><strong>{$title}{$typeName}</strong></li>
</ol>

{/block}

{block name="main"}
<div class="ibox float-e-margins">
    <div class="ibox-title">
        <h5>{$title}{$typeName}</h5>
    </div>
    <div class="ibox-content">
        <form method="post" class="form-horizontal" onsubmit="return toSubmit()">
            <div class="form-group">
                <label class="col-sm-2 control-label">{$typeName}名称</label>
                <div class="col-sm-6">
                    <input type="text" name="file_name" value="{$model ? $model.file_name : ''}" class="form-control"
                           required/>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">上传{$typeName}</label>
                <div class="col-sm-10">
                    <div id="container">
                        <input type="hidden" name="file" id="container-input" value="{$model ? $model.file : ''}">
                        <div id="file-container">
                            {if ( $model && $model.file ) }
                            <p>
                                {if ($model.type == 1) }
                                <video src="{:config('file_prefix').$model.file}" controls="controls" class="my-video">
                                    您的浏览器不支持 video 标签。
                                </video>
                                {elseif ($model.type == 2) }
                                <audio src="{:config('file_prefix').$model.file}" controls="controls">
                                    您的浏览器不支持 audio 标签。
                                </audio>
                                {else /}
                                <button type="button" data-file="{:config('file_prefix').$model.file}"
                                        class="read-one btn btn-primary">点击查看
                                </button>
                                {/if}
                            </p>
                            {/if}
                        </div>
                        <br/>
                        <a href="javascript:void(0);" id="select-container" class='btn btn-primary'>选择文件</a>
                        <a href="javascript:void(0);" id="post-container" class='myPostFiles btn btn-primary'>开始上传</a>
                        <span>（格式：{$uploadFormat}，大小：{$uploadSize}以内）</span>
                    </div>
                </div>
            </div>

            {if $type == 1}
            <div class="form-group">
                <label class="col-sm-2 control-label">是否免费</label>
                <div class="col-sm-6">
                    <select name="is_free" class="form-control" required>
                        {foreach $isFree as $key=>$vo }
                        {if ( $model && $model.is_free == $key ) }
                        <option value="{$key}" selected>{$vo}</option>
                        {else /}
                        <option value="{$key}">{$vo}</option>
                        {/if}
                        {/foreach}
                    </select>
                </div>
            </div>
            {/if}

            <div class="form-group">
                <label class="col-sm-2 control-label">权重</label>
                <div class="col-sm-6">
                    <input type="text" name="sort_num" value="{$model ? $model.sort_num : 0}" class="form-control"/>
                </div>
            </div>

            {if $type == 2}
            <div class="form-group">
                <label class="col-sm-2 control-label">描述</label>
                <div class="col-sm-6">
                    <textarea name="description" id="editor" style="width:650px;height:200px;">{$model ? $model.description : ''}</textarea>
                </div>
                {load href="/static/js/plugins/ueditor/ueditor.config.js" /}
                {load href="/static/js/plugins/ueditor/ueditor.all.min.js" /}
                {load href="/static/js/plugins/ueditor/lang/zh-cn/zh-cn.js" /}
                <script>
                    UE.getEditor('editor', {
                        serverUrl: "{:url('u_editor/upload')}"
                    });
                </script>
            </div>
            {/if}

            <div class="form-group">
                <label class="col-sm-2 control-label">状态</label>
                <div class="col-sm-6">
                    <select name="status" class="form-control" required>
                        {foreach $status as $key=>$vo }
                        {if ( $model && $model.status == $key ) }
                        <option value="{$key}" selected>{$vo}</option>
                        {else /}
                        <option value="{$key}">{$vo}</option>
                        {/if}
                        {/foreach}
                    </select>
                </div>
            </div>

            <div class="hr-line-dashed"></div>
            <div class="form-group">
                <div class="col-sm-4 col-sm-offset-2">
                    {if ( $model && $model.id > 0) }
                    <input type="hidden" name="id" value="{$model.id}">
                    {/if}
                    <input type="hidden" name="lang" value="{$lang}">
                    <input type="hidden" name="className" value="{$className}">
                    <input type="hidden" name="class_id" value="{$classId}">
                    <input type="hidden" name="course_type" value="{$courseType}">
                    <input type="hidden" name="type" value="{$type}">
                    <button class="btn btn-primary" type="submit" id="mySubmitBtn">提交</button>
                    <button class="btn btn-white" type="button"><a
                            href="{:url('index', ['classId' => $classId, 'courseType' => $courseType, 'type' => $type, 'lang' => $lang, 'className' => $className])}">取消</a>
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
{/block}

{block name="jsFile"}
{load href="/static/js/plugins/plupload/js/plupload.full.min.js" /}
<script>
    window.PHP = {
        containerIds: ['container'],
        uploadUrl: "{:url('upload/file', ['type' => $uploadType, 'dir' => 'lang_file'])}",
        maxSize: "{$uploadSize}",
        fileNum: 1,
        extensions: ["{$uploadFormat}"],
    };
    $('#container').on('click', '.read-one', function () {

        window.open($(this).data('file'))
    })
</script>
{load href="/static/js/plugins/plupload/upload.js" /}
{/block}